package com.jn.listtest_2;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


import com.jn.listtest_2.adapter.StudentBaseAdapter;
import com.jn.listtest_2.bean.Student;

import java.util.ArrayList;
import java.util.List;

public class BaseAdapterActivity extends AppCompatActivity {
    private ListView mListView;
    private List<Student> mList;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        mListView = findViewById(R.id.listview);
        initData();
        StudentBaseAdapter adapter = new StudentBaseAdapter(mList, this);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Student student = (Student) view.getTag(R.integer.tag_key);
                Student student1 = (Student) parent.getItemAtPosition(position);
                Log.e("test123", "====================" + student);
            }
        });
    }

    private void initData() {
        mList = new ArrayList<>();
        Student student;
        for (int i = 0; i < 31; i++) {
            student = new Student();
            student.setName("刘小" + i);
            student.setNumber("00000000" + i);
            mList.add(student);
        }
    }
}